﻿using System;
using System.Globalization;
using System.Web.Mvc;
using ControllersAndActions.Infrastructure;

namespace ControllersAndActions.Controllers
{
    public class DerivedController : Controller
    {
        //
        // GET: /Derived/
        public ActionResult Index()
        {
            ViewBag.Message = "Hello from the Derived controller index method";
            return View("MyView");
        }

        public ActionResult RenameProduct()
        {
            // Access various properties from context objects
            string userName = User.Identity.Name;
            string serverName = Server.MachineName;
            string clientIP = Request.UserHostAddress;
            DateTime dateStamp = HttpContext.Timestamp;
            //AuditRequest(userName, serverName, clientIP, dateStamp, "Renaming product");
            // Retrieve posted data from Request.Form
            //string oldProductName = Request.Form["OldName"];
            //string newProductName = Request.Form["NewName"];
            //bool result = AttemptProductRename(oldProductName, newProductName);
            //ViewData["RenameResult"] = result;

            ViewBag.Message = string.Format("{0}; {1}; {2}; {3}; ", userName, serverName, clientIP, dateStamp);
            return View("MyView");
        }

        public ActionResult ProduceOutput()
        {
            if (String.Compare(Server.MachineName.ToUpper(), "MEGAWS", StringComparison.Ordinal) == 0)
            {
                return new CustomRedirectResult { Url = "/Basic/Index" };
            }
            else
            {
                Response.Write("Controller: Derived, Action: ProduceOutput");
                return null;
            }
        }

        public ActionResult ProduceOutput2()
        {
            return new RedirectResult("/basic/index");
        }

    }
}